﻿using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace Steer
{
	public partial class FleeTest : UserControl
    {
        public bool IsFocus = false;

        protected override void OnLostFocus(RoutedEventArgs e)
        {
            IsFocus = false;
            PauseMask.Visibility = IsFocus ? Visibility.Collapsed : Visibility.Visible;
            base.OnLostFocus(e);
        }

        protected override void OnGotFocus(RoutedEventArgs e)
        {
            IsFocus = true;
            PauseMask.Visibility = IsFocus ? Visibility.Collapsed : Visibility.Visible;
            base.OnGotFocus(e);
        }
        double mouseX = 0;
        double mouseY = 0;
		public FleeTest()
		{
			// Required to initialize variables
            InitializeComponent();
            Loaded += new RoutedEventHandler(SeekTest_Loaded);
        }

        void SeekTest_Loaded(object sender, RoutedEventArgs e)
        {
            myStar.position = new Vector2D(100, 100);
            myStar.edgeBehavior = Vehicle.BOUNCE;
            myStar.velocity.length = 5;
            myStar.velocity.angle = Math.PI / 4;

            MouseMove += new MouseEventHandler(SeekTest_MouseMove);
            CompositionTarget.Rendering += new EventHandler(CompositionTarget_Rendering);
        }

        void CompositionTarget_Rendering(object sender, EventArgs e)
        {
            if (IsFocus)
            {
                myStar.flee(new Vector2D(mouseX, mouseY));
                myStar.update();
            }
        }

        void SeekTest_MouseMove(object sender, MouseEventArgs e)
        {
            mouseX = e.GetPosition(null).X;
            mouseY = e.GetPosition(null).Y;
        }
    }
}